<template>
	<view>
		<view class="u-margin-left-20 u-margin-right-20 u-margin-bottom-20">
			<u-search placeholder="请输入关键字搜索" v-model="keyword"  @search="clickSearch(value)"
			 :focus="true" action-text="取消" @custom="cancelSearch"></u-search>
		</view>
		<u-gap height="20" bg-color="#f7f7f7"></u-gap>
		<view class="hot" >
			<view class="title">热门搜索</view>
			<view class="body">
				<view class="tag" v-for="(item,index) in hotList" :key="index">{{item}}</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				keyword:"",
				hotList:['床体安装','柜类安装','灯具安装','地暖安装',
				'油烟机清洗','日常保洁','玻璃清洁']
			}
		},
		methods: {
			clickSearch(){
				if(this.keyword === ''){
					return uni.showToast({
						title: '关键词不能为空',
						icon: 'none'
					});
				}else{
					uni.hideKeyboard()
				}
			},
			// 自定义取消搜索事件
			cancelSearch(){
				uni.navigateBack({
					delta: 1
				})
			},
			clickSearchTag(item){
				this.keyword = item
				this.clickSearch()
			},
		}
	}
</script>

<style>
	page {
		background: #FFFFFF;
	}
</style>

<style lang="scss" scoped>
	.hot{
		.title {
		    font-size: 28rpx;
		    color: $u-content-color;
			margin: 30rpx 20rpx;
		}
		
		.body{
			.tag {
				display: inline-block;
				width: 150rpx;
				height: 60rpx;
				line-height: 60rpx;
			    font-size: 26rpx;
			    color: $u-content-color;
			    margin: 0 10rpx 20rpx;
				padding: 5rpx 10rpx;
				text-align: center;
				background-color: $u-bg-color;
				border-radius: 8rpx;
			}
		}
	}
</style>
